package net.xdclass.online_xdclass.config;

import net.xdclass.online_xdclass.interceptor.CorsInterceptor;
import net.xdclass.online_xdclass.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    @Configuration
    public class InterceptorConfig implements WebMvcConfigurer {

//LoginInterceptor这个是拦截器的名字 在这里是把它写入容器使其可以调用
        @Bean
        LoginInterceptor loginInterceptor() {
            return new LoginInterceptor();
        }
        @Bean
CorsInterceptor corsInterceptor(){
            return new CorsInterceptor();
}

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
//拦截全部一定要在最前面  跨域操作
            registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");



            registry.addInterceptor(loginInterceptor()).addPathPatterns("/api/v1/pri/*/*/**")
                    //不拦截哪些路径   斜杠一定要加
                    .excludePathPatterns("/api/v1/pri/user/login", "/api/v1/pri/user/register");

            WebMvcConfigurer.super.addInterceptors(registry);

        }

    }